﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace Irandeb4.Models
{
    public class RequiredNumberAttribute : RequiredAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            bool valid = false;
            string error = "el NIT solo permite numeros";
            if (value is string && value != null)
            {
                string sval = value as string;

                long number;
                bool isNumber = long.TryParse(sval, out number);

                if (isNumber)
                    valid = true;

            }

            if (base.IsValid(value) && valid)
                return ValidationResult.Success;
            else
                return new ValidationResult(error);
        }
    }
}